package com.inspur.iaic.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.inspur.iaic.data.NginxLog;

/**
 * 
 * 日志推送服务
 *
 */
@Component
public class LogSendService {
	private final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private SimpMessagingTemplate messagingTemplate;

	@Async
	public void send(String topic, NginxLog nginxLog) {
		try {
			if (nginxLog != null) {
				messagingTemplate.convertAndSend(topic, nginxLog);
			}
		} catch (MessagingException e) {
			log.error("推送失败：" + nginxLog, e);
		}
	}

}